<template>
  <view>
    <u-navbar title="工作台" :leftIcon="false"> </u-navbar>
    <view v-for="(item, key) in showlist" :key="key">
      <view class="title">{{ item.title }}</view>
      <view class="listbox">
        <view class="item" v-for="(item2, key2) in item.list" :key="key2" @click="gourl(item2.url)">
          <!-- <image :src="item2.icon" mode="widthFix"></image> -->

          <u--image :src="item2.icon" width="60rpx" height="60rpx"></u--image>
          <view class="text">{{ item2.title }}</view>
        </view>
      </view>
    </view>
    <tabbar></tabbar>
  </view>
</template>

<script>
export default {
  data() {
    return {
      list: [
        {
          title: "公司管理",
          list: [
            {
              title: "公司信息",
              url: "/pageswork/company/companyInfo/companyInfo",
              icon: "/static/images/work/gongsiXx.png",
              perm: ["company:companyInfo:query"],
            },
            {
              title: "企业资料",
              url: "/pageswork/company/fileInfo/list",
              icon: "/static/images/work/buluHt.png",
              perm: ["enterprise:file-info:query"],
            },
            {
              title: "企业人员",
              url: "/pageswork/company/empInfo/empInfo",
              icon: "/static/images/work/qiyeRy.png",
              perm: ["emp:info:query"],
            },
          ],
        },
        {
          title: "合同管理",
          list: [
            {
              title: "起草合同",
              url: "/pageswork/contract/draft/draft",
              icon: "/static/images/work/buluHt.png",
              perm: ["contractManage:info:list"],
            },
            {
              title: "补录合同",
              url: "/pageswork/contract/supplementary/supplementary",
              icon: "/static/images/work/buluHt.png",
              perm: ["contractManage:info:list"],
            },
          ],
        },
        {
          title: "财务管理",
          list: [
            {
              title: "收入管理",
              url: "/pageswork/finance/income/income",
              icon: "/static/images/work/shouru.png",
              perm: ["internal:incomeRecord:list"],
            },
            {
              title: "支出管理",
              url: "/pageswork/finance/expenditure/expenditure",
              icon: "/static/images/work/zhichu.png",
              perm: ["internal:expenditureRecord:list"],
            },
          ],
        },
        {
          title: "应用管理",
          list: [
            {
              title: "每日广告情况",
              url: "/pageswork/appman/oneDay/list",
              icon: "/static/images/work/sjtj.png",
              perm: [
                "appletManage:slot:page"
              ],
            },
            {
              title: "结算情况",
              url: "/pageswork/appman/settlement/list",
              icon: "/static/images/work/yjcx.png",
              perm: [
                "appletManage:settlement:page"
              ],
            },
          ],
        },
        {
          title: "项目管理",
          list: [
            {
              title: "项目管理",
              url: "/pageswork/project/projectInfo/list",
              icon: "/static/images/work/xiangmuGl.png",
              perm: [
                "project:type:query"
              ],
            },
            {
              title: "项目类型",
              url: "/pageswork/project/projectType/list",
              icon: "/static/images/work/xiangmuLx.png",
              perm: [
                "project:info:query"
              ],
            },
          ],
        },
      ],
    };
  },
  computed: {
    showlist() {
      let rlist = this.list.map((e) => {
        return {
          ...e,
          list: e.list.filter((e2) => {
            return e2.perm ? this.inserted(e2.perm) : true;
          }),
        };
      });
      rlist = rlist.filter((e) => e.list.length > 0);
      return rlist;
    },
  },
  methods: {
    inserted(permissionFlag) {
      const all_permission = "*:*:*"; // 全部权限
      const permissions = this.$store.state.user.permissions || []; // 用户拥有的权限标识的数组

      const hasPermissions = permissions.some((permission) => {
        return (
          all_permission === permission || permissionFlag.includes(permission)
        );
      });
      return hasPermissions ? true : false;
    },
    gourl(url) {
      uni.navigateTo({
        url: url,
      });
    },
  },
};
</script>

<style lang="scss">
.title {
  font-size: 28rpx;
  display: flex;
  align-items: center;
  background-color: #f9f9f9;
  padding: 0 20rpx;
  height: 88rpx;
}

.listbox {
  background: #fff;
  display: flex;
  flex-wrap: wrap;

  .item {
    width: 25%;
    height: 25vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    .text {
      margin-top: 10rpx;
      font-size: 28rpx;
    }
  }
}
</style>
